Optimisation of operation

Table of Contents

1. Introduction

This document contains a description of optimisation tools for electric system operation simulation. If you are interested in planing you might prefer to switch directly to file optim-Planing.ipynb. In files BasicFunctionalities/input-XXX.ipynb you can learn to understand input data (consumption, availability).

This document will gives a chance to understand

It proposes to enter the subject by increasing progressively the number of variables and constraints in the optimisation problem, hence moving toward more realism through the document, introducing:

It relies on different test cases that allow to

If, after reading this file, you want to build your own pyomo model you can go to optim-Operation-Advanced.ipynb.

2. First basic problem

In this section we propose a simple version of the optimisation problem with a mathematical description. This allows us to discuss the use of pyomo (a python package to write optimisation problems).

2.1. Math and first step with pyomo for solving problem

Mathematical formulation as a linear programming problem

\begin{align} &\text{Cost function }& &\min_{x} \sum_t \sum_i \pi_i x_{it}\;\;\; & & \pi_i \text{ marginal cost}\\ &\text{Power limit } & &\text{ s.t.} \;\; 0 \leq x_{it}\leq a_{it} \bar{x_i} & &\bar{x_i} \text{ installed power, } a_{it} \text{ availability}\\ &\text{Meet demand } & & \sum_i x_{it} \geq C_t && C_t \text{ Consumption}\\ &\text{Stock limit } & &\sum_t x_{it}\leq E_i && E_i=\bar{x_i}*N_i \text{ Energy capacity limit}\\ \end{align}

This is linear programing and could be transformed into something like

$ \begin{align} & \min_y & c^Ty \\ & Ay\leq b \end{align} $

with a well chosen parameter matrix $A$, parameter vector $b$ and $c$ and variable vector $y$. While increasing complexity of the problem, this can become very painful.

With the Python package Pyomo it is almost sufficient to write the mathematical equations. Pyomo is then charged of building the matrix form, and you just have to think about problem formulation. Pyomo is similar to other tools such as GAMS, AMPL, ...

Principles of a pyomo model To build a model, Pyomo needs three different kinds of data : sets, parameters and variables.

Now if you wish to learn more about pyomo and to see how the optimisation problem is writen in pyomo language, take look at function GetElectricSystemModel_GestionSingleNode (by doing a control-click on it in the code that follos a bit later, otherwise it is in functions/f_operationModels.py). We will use this function in the following exemple.

First simulation -- loading parameters

We start with the simple test case bellow, with only two production means (nuke and thermal) but you can run this with more than that, and change the installed power. If you want to change assumptions you will need to change the csv files that are loaded below.

First simulation -- running the optimisation

Now we run the optimisation script and load optimised variables.

At this stage, or later, you might be willing to to see the pyomo model. If it is the case, dig into function GetElectricSystemModel_GestionSingleNode (by doing a control-click on it, otherwise it is in functions/f_operationModels.py)

We have analysed the result of the optimisation first with the dictionary variables that contains all optimized variables. The most important variable here is 'energy'. The other one 'energyCosts' can be computed from 'energy' and it is somehow redundant.

2.2 Analysing results : lagrange multipliers

Lagrange multiplier might be more difficult to understand for those who still lack a good optimisation course (the one at second semester of first year of MINES ParisTech is perfect). In cases you want to dig this, you can have a look at Boyd's course, e.g. starting with lecture 8 or before. The most important message here is that lagrange multipliers associated to the demand constraint (here called 'energyCtr') are meant to mimic market prices. Lagrange multiplier associated to this constraint at time t is the marginal cost that one would pay to increase $C_t$ by a small amount. They can be used to simulate market prices.

We have the Lagrange multipliers associated to each (active) constraint (zero means unactive constraint) in dictionary 'Constraints'. We have three different constraints : the energy constraint, the capacity constraint and the storage constraint (unactive here) Try understanding the meaning of lagrange multipliers, here and in the next Sections.

3. Extensions of this operation problem

3.1. Linear temporal coupling with ramp constraints

In the this section, we will increase the complexity of the problem given in Section 2 and add : dependency on area z (country), a congestion constraint, ramp constraints.

\begin{align} &\text{Cost function }& &\min_{x} \sum_z \sum_t \sum_i \pi_{iz} x_{itz}\;\;\; & & \pi_{iz} \text{ marginal cost}\\ &\text{Power limit } & &\text{ s.t.} \;\; 0 \leq x_{itz}\leq a_{itz} \bar{x_{iz}} & &\bar{x_{iz}} \text{ installed power, } a_{itz} \text{ availability}\\ &\text{Meet demand } & & \sum_i x_{itz} \geq C_{tz} && C_{tz} \text{ Consumption}\\ &\text{Stock limit } & &\sum_t x_{it}\leq E_i && E_i=\bar{x_i}*N_i \text{ Energy capacity limit}\\ &\text{ramp limit } & &rc^-_i *x_{it}\leq x_{it}-x_{i(t+1)}\leq rc^+_i *x_{it} && rc^+_i rc^-_i\text{ ramp limit}\\ \end{align}

Again you can have to look at lagrange multipliers. Try adding renewable production.

Try modifying the ramp constraint to generate negative lagrange multipliers.

3.2. Linear spatial coupling with spatial constraints

Math here are in 3.1

4. Storage operation

4.1. Optimisation of a storage market participation

Just have a look at optim-Storage.ipynb

4.2. Simultaneous optimisation of storage and electric system

This section is a bit more difficult that the other one. You can skip the math if you're only interested in using the storage optimisation tool.

Let us define $\psi : z\in \mathbb{R}^T \rightarrow \psi(z)\in \mathbb{R}$ as the solution to the simple operation problem

\begin{align} &\text{Cost function }& &\min_{x} \sum_t \sum_i \pi_i x_{it}\;\;\; & & \pi_i \text{ marginal cost}\\ &\text{Power limit } & &\text{ s.t.} \;\; 0 \leq x_{it}\leq a_{it} \bar{x_i} & &\bar{x_i} \text{ installed power, } a_{it} \text{ availability}\\ &\text{Meet demand } & & \sum_i x_{it} \geq C_t+z_t && C_t \text{ Consumption}\\ &\text{Stock limit } & &\sum_t x_{it}\leq E_i && E_i=\bar{x_i}*N_i \text{ Energy capacity limit}\\ \end{align}

Adding one storage to this operation problem is done here : \begin{align} &\text{Cost function }& &\min_{z} \psi(z) \\ &\text{storage power constraint}& &-p_{\max}\leq z_i\leq p_{\max} \\ &\text{storage energy constraint}& &-p_{\max}\leq \sum_{j=1}^i z_j\leq p_{\max} \\ \end{align}

Note that $\psi(z)=\sum_i \psi_i(z_i)$. When we solve the planing problem with a value of storage operation $z^0$ this not only provides $\psi(z^0)$ but also the gradient $\nabla \psi(z^0)$ (with Lagrange multipliers), and if we denote $\delta^0_i=(\nabla \psi(z^0))_i$ it entails a convenient uniform lower bound on $\psi(z)$ :

$ \begin{align} &\beta^0(z)& = &\;\; \langle \nabla \psi(z^0),z-z^0\rangle +\psi(z^0) \\ & & = & \;\;\sum_i \;\;\delta^0_i z_i+ \psi_i(z_i^0) -\delta^0_iz_i^0 \\ & & \hat{=} & \;\;\sum_i \beta_i^0(z_i) \end{align} $

As a consequence, an iterative procedure is implemented to solve this problem,

This algorithm is implemented in function GetElectricSystemModel_GestionSingleNode_with1Storage in file functions/f_operationModels.py. The idea of this algorithm is quite general and a version exists also in the multi-node case and for planing problems (in file functions/f_planingModels.py)

If you want to contribute here, try improving the visualisation tools (with respect to storage, multizone, integration of interconnexions ...)

5. Complete French case

If you want to contribute here :